/*
 * WindowController.java
 * Created on 2010-dec-02, 09:17:49
 */

package simplepushclient;

/**
 * @author Filip
 */
public class WindowController extends javax.swing.JFrame {
    private PusherTray parent;
    private Sender s;
    private boolean sentOpen=false;

    /** Creates new form WindowController */
    public WindowController(PusherTray parent) {
        this.parent=parent;
        this.s = new Sender( parent.getIp() );
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        closeButton = new javax.swing.JButton();
        Maximize = new javax.swing.JButton();
        winShiftWindow = new javax.swing.JButton();
        minimize = new javax.swing.JButton();
        shiftWindow = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Window control");
        setResizable(false);

        closeButton.setText("Close Window");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        Maximize.setText("Maximize");
        Maximize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MaximizeActionPerformed(evt);
            }
        });

        winShiftWindow.setText("-#>");
        winShiftWindow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                winShiftWindowActionPerformed(evt);
            }
        });

        minimize.setText("Minimize");
        minimize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minimizeActionPerformed(evt);
            }
        });

        shiftWindow.setText("->");
        shiftWindow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shiftWindowActionPerformed(evt);
            }
        });

        jButton2.setText("Nothing");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(closeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(minimize, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                    .addComponent(Maximize, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(shiftWindow, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                    .addComponent(winShiftWindow, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(closeButton)
                    .addComponent(winShiftWindow)
                    .addComponent(Maximize))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(minimize, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(shiftWindow)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        push("nircmd:sendkeypress alt+F4");
    }//GEN-LAST:event_closeButtonActionPerformed

    private void winShiftWindowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_winShiftWindowActionPerformed
        push("nircmd:sendkeypress lwin+tab");
        push("nircmd:sendkey lwin down");
        push("nircmd:sendkeypress tab");
        push("nircmd:sendkey lwin up");
    }//GEN-LAST:event_winShiftWindowActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if(sentOpen){
            push("nircmd:cdrom close");
         }else{
            push("nircmd:cdrom open");
        }
        sentOpen = (!sentOpen);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void shiftWindowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shiftWindowActionPerformed
        push("nircmd:sendkey alt down");
        push("nircmd:sendkeypress tab");
        push("nircmd:sendkey alt up");
    }//GEN-LAST:event_shiftWindowActionPerformed

    private void MaximizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MaximizeActionPerformed
        push("press:alt+space");
        push("press:x");
    }//GEN-LAST:event_MaximizeActionPerformed

    private void minimizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minimizeActionPerformed
        push("press:alt+space");
        push("press:n");
    }//GEN-LAST:event_minimizeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Maximize;
    private javax.swing.JButton closeButton;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton minimize;
    private javax.swing.JButton shiftWindow;
    private javax.swing.JButton winShiftWindow;
    // End of variables declaration//GEN-END:variables

    private void push(String t){
        s.setData(t);
        s.run();
    }
}
